<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Edit</title>
    <div th:replace="~{fragments/headTag :: headTag}"></div>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm"
        crossorigin="anonymous"></script>
<nav th:replace="~{fragments/bodyHeader :: bodyHeader}"></nav>
<!--@thymesVar id="payment" type="ru.tbcarus.spendingsb.model.Payment"-->
<!--@thymesVar id="paymentType" type="ru.tbcarus.spendingsb.model.PaymentType"-->
<!--@thymesVar id="user" type="ru.tbcarus.spendingsb.model.User"-->
<div class="position-absolute top-50 start-50 translate-middle">
    <form th:method="POST" th:action="@{/payments}" th:object="${payment}" class="form">
        <input type="hidden" name="id" th:value="${payment.id}">
        <table class="table shadow table-striped">
            <tr>
                <td colspan="2" class="text-center">
                    <input th:if="${payment.id}" type="button" class="btn btn-del" value="Удалить запись"
                           th:onclick="|window.location.href = 'delete?id=${payment.id}'|"
                           th:method="delete">
                </td>
            </tr>
            <tr th:if="${user.isInGroup()}">
                <td th:unless="${payment.isNew()}" colspan="2" class="text-center">
                    <span th:text="${payment.user.getName()} + ' (' + ${payment.user.getEmail()} + ')'">Пользователь</span>
                </td>
            </tr>
            <tr>
                <td class="d-flex justify-content-end">
                    <b>Тип:</b>
                </td>
                <td>
                    <select name="type" class="rounded-2 border-1">
                        <option th:unless="${payment.isNew()}" th:value="${payment.type}"
                                th:text="${payment.type.title}">DEFAULT
                        </option>
                        <option th:each="paymentType : ${T(ru.tbcarus.spendingsb.model.PaymentType).values()}"
                                th:value="${paymentType}" th:text="${paymentType.title}">Type
                        </option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="d-flex justify-content-end">
                    <b>Сумма:</b>
                </td>
                <td>
                    <!--                    <input type="text" name="price" th:value="${payment.price}" class="rounded-2 border-1">-->
<!--                    <label for="price">Сумма:</label>-->
                    <input type="text" class="rounded-2 border-1" id="price" name="price" th:field="*{price}" th:value="*{price}">
                    <p class="alert alert-danger" th:if="${#fields.hasErrors('price')}" th:errors="*{price}"></p>
                </td>
            </tr>
            <tr>
                <td class="d-flex justify-content-end">
                    <b>Описание:</b>
                </td>
                <td>
                    <input type="text" name="description" th:value="${payment.description}" class="rounded-2 border-1">
                </td>
            </tr>
            <tr>
                <td class="d-flex justify-content-end">
                    <b>Дата:</b>
                </td>
                <td>
                    <input type="date" name="date" th:value="${payment.date}" class="rounded-2 border-1">
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <div class="d-flex justify-content-around">
                        <button type="submit" class="btn btn-top">Сохранить</button>
                        <input type="button" value=" Отменить " class="btn btn-top" th:onclick="|window.location.href='@{/payments}'|">
                    </div>
                </td>
            </tr>
        </table>
    </form>
    <!--    copyright-->
    <div th:replace="~{fragments/footer :: copy}"></div>
</div>
</body>
</html>